<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopOrderItemTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('shop_order_item', ['comment' => '订单商品', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('order_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '订单'])
            ->addColumn('user_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '用户'])
            ->addColumn('goods_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '商品'])
            ->addColumn('goods_sku_price_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '规格'])
            ->addColumn('activity_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '活动'])
            ->addColumn('activity_type', 'string', ['limit' =>  255, 'null' => true, 'default' => null, 'comment' => '活动类型'])
            ->addColumn('promo_types', 'string', ['limit' =>  255, 'null' => true, 'default' => null, 'comment' => '营销类型'])
            ->addColumn('item_goods_sku_price_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '活动规格|积分商城规格'])
            ->addColumn('goods_sku_text', 'string', ['limit' => 60, 'null' => true, 'default' => null, 'comment' => '规格名'])
            ->addColumn('goods_title', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '商品名称'])
            ->addColumn('goods_image', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '商品图片'])
            ->addColumn('goods_original_price', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '商品原价'])
            ->addColumn('goods_price', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '商品价格'])
            ->addColumn('goods_num', 'integer', ['limit' => 10, 'default' => 0, 'comment' => '购买数量'])
            ->addColumn('goods_weight', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '商品重量(KG)'])
            ->addColumn('discount_fee', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '优惠费用'])
            ->addColumn('pay_fee', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '支付金额(不含运费)'])
            ->addColumn(Column::tinyInteger('dispatch_status')->setDefault(0)->setUnsigned()->setComment('发货状态:0=未发货,1=已发货,2=已收货'))
            ->addColumn('dispatch_fee', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '发货费用'])
            ->addColumn('dispatch_type', 'string', ['limit' => 60, 'null' => true, 'default' => null, 'comment' => '发货方式'])
            ->addColumn('dispatch_id', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '发货模板'])
            ->addColumn(Column::tinyInteger('aftersale_status')->setDefault(0)->setComment('售后状态:-1=拒绝,0=未申请,1=申请售后,2=售后完成'))
            ->addColumn(Column::tinyInteger('comment_status')->setDefault(0)->setComment('评价状态:0=未评价,1=已评价'))
            ->addColumn(Column::tinyInteger('refund_status')->setDefault(0)->setComment('退款状态:0=未退款,1=已同意,2=已完成'))
            ->addColumn('refund_fee', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '退款金额'])
            ->addColumn('refund_msg', 'string', ['limit' => 10, 'null' => true, 'default' => null, 'comment' => '退款原因'])
            ->addColumn('order_express_id', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '快递包裹'])
            ->addColumn('ext', 'string', ['limit' => 2048, 'null' => true, 'default' => null, 'comment' => '附加信息'])
            ->addColumn('create_time', 'integer', ['limit' => 10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit' => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addIndex('order_id')
            ->addIndex('user_id')
            ->addIndex('goods_id')
            ->addIndex('activity_id')
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('shop_order_item');
        $table->drop();
    }
}
